package com.weng.cloud.starter.dataSource.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.batch.BatchDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @Author: weng
 * @Date: 2022/3/19
 * @Description: com.weng.cloud.starter.db.config
 */
//@Configuration
public class SpringDataSourceAutoConfiguration {

    @Bean
//    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    @BatchDataSource
    public DataSource dataSource(){
        return DataSourceBuilder.create().build();
    }

/*
    @Bean(name = "primaryDataSource")
    @Qualifier("primaryDataSource")
    @Primary
    @ConfigurationProperties(prefix = "spring.datasource.primary")
    public DataSource primaryDataSource(){
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "readDataSource")
    @Qualifier("readDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.read")
    public DataSource readDataSource(){
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "writeDataSource")
    @Qualifier("writeDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.write")
    public DataSource writeDataSource(){
        return DataSourceBuilder.create().build();
    }
*/
}
